home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8412 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Checking for Ilegal Input
  5. Date: 4 Mar 1996 09:15:40 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4hecbs$qf2@hpbblb.bbn.hp.com>
  8. References: <313855C7.5E86@aol.com>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:313855C7.5E86@aol.com
  15.  
  16. gregace@aol.com wrote:
  17. >I have a program where you must enter a number between 0 and 15 and check for 
  18. >illegal input such as a number not between 0 and 15 or if a character is 
  19. >entered.
  20. >
  21. >I used the scanf("%d",&number) to read the input.
  22. >
  23. >I check the illegal input by
  24. >
  25. >while (number<0 or number>15)
  26. >{ Printf("Enter a again:");
  27. >  scanf("%d",&number);
  28. >}
  29. >
  30. >This check works fine accept when the user enters a character such as the 
  31. >letter f. Does anyone know how to check illegal input that is not a number?
  32. >
  33. Check the return value of scanf. It gives the number of successfully assigned
  34. input items or EOF. In case of entering characters it returns 0.
  35.  
  36. Good luck,
  37. Matthias
  38.  
  39.